﻿/************************************************
*
* Copyright(c) ZeeGuo.com
*
* CLR : 4.0.30319.296
*
* FileName : Entity178ComicBook.cs
*
* Author : Kurodo
*
* CreatTime : 2013/6/24 16:08:31
*           
*************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using ComicSpider.Model;
using HtmlAgilityPack;

namespace ComicSite
{
    public class Entity178ComicBookList : EntityComicBookList
    {
        protected override string GetWebSiteUrl()
        {
            return "http://www.dmzj.com";
        }

        protected override string GetKeyCode(string context)
        {
            return DataMatch.RegexsValue(context, "var g_comic_url = \"(\\w{1,10})", 1);
        }

        protected override string GetAuthor(string context)
        {
            return DataMatch.RegexsValue(context, "<th>作者：</th>([\\s]*)<td><a href='../tags/(\\w{1,10}).shtml'>(\\w{1,10}) </a><br/></td>", 3);
        }

        protected override string GetAddress(string context)
        {
            return DataMatch.RegexsValue(context, "<th>地域：</th>([\\s]*)<td><a href=\"../tags/(\\w{1,10}).shtml\" alt=\"(\\w{1,10})\">(\\w{1,10})</a></td>", 4);
        }

        protected override string GetState(string context)
        {
            return DataMatch.RegexsValue(context, "<th>状态：</th>([\\s]*)<td><a href=\"../tags/(\\w{1,20}).shtml\" alt=\"(\\w{1,10})\">(\\w{1,10})</a></td>", 4);
        }

        protected override string GetSubject(string context)
        {
            return DataMatch.RegexsValue(context, "<th>题材：</th>([\\s]*)<td><a href='../tags/(\\w{1,10}).shtml'>(\\w{1,10})</a>&nbsp;", 3);
            //string result = DataMatch.RegexValue(context,"<th>题材：</th>([\\s]*)<td>([<a href='../tags/\\w{1,10}.shtml'>\\w{1,10}</a>&nbsp;]*)</td>",2);
            //return DataMatch.RegexValue(result, "(\\w{1,10})</a>&nbsp;");
        }

        protected override string GetCategory(string context)
        {
            return DataMatch.RegexsValue(context, "<th>分类：</th><td><a title='(\\w{1,10})' href='../tags/(\\w{1,10}).shtml'>(\\w{1,10})</a></td>", 3);
        }

        protected override string GetUpdate(string context)
        {
            string formula = "<th>最新收录：</th>([\\s]*)<td ><a href=\"/" + this.Comic_KeyCode + "/(\\w{1,10}).shtml\"  id=\"newest_chapter\">(\\w{1,10})</a>&nbsp;<br /><span class=\"update2\">(\\d{4}-\\d{2}-\\d{2})</span></td>";
            return DataMatch.RegexsValue(context, formula, 3, 4);
     }

        protected override string GetHotNum(string context)
        {
            return DataMatch.RegexsValue(context, "<th>人气：</th>([\\s]*)<td>(\\d{1,10})</td>", 2);
        }

        protected override string GetBookName(string context)
        {
            return DataMatch.RegexsValue(context, "g_comic_name = \"(\\w{1,50})\";", 1);
        }

        protected override string GetOldName(string context)
        {
            return DataMatch.RegexsValue(context, "<th>原名：</th>([\\s]*)<td> (\\w{1,10})</td>", 2);
        }

        protected override string GetOtherName(string context)
        {
            return DataMatch.RegexsValue(context, "<th>别名：</th>([\\s]*)<td> (\\w{1,10})</td>", 2);
        }

        public override List<EntityComicBook> GetComicList(string context)
        {
            List<EntityComicBook> list = new List<EntityComicBook>();
            HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml(context);

            HtmlNode html = doc.DocumentNode;
            HtmlNodeCollection books = html.SelectNodes("//div[@class='cartoon_online_border']//a[@href]");
            if (books != null)
            {
                foreach (HtmlNode link in books)
                {
                    HtmlAttribute att = link.Attributes["href"];
                    Entity178ComicBook comics = new Entity178ComicBook();
                    comics.UrlAddress = string.Format("{0}{1}", this.Comic_WebSiteUrl, att.Value);
                    comics.Comic_BookName = link.InnerText;
                    list.Add(comics);
                }
            }

            return list;
        }
    }
}
